import '../../../common/http/global.dart';
import '../../../common/http/http_util.dart';

class Api {
  DioClient dioClient = DioClient();
  Future getMeData<T>([bool showLoading = true]) async {
    try {
      Map<String, dynamic> response =
          await dioClient.get('$baseUrl/me/getMeData');
      if (response is Map) {
        String tel = response['person']['tel'];
        tel = tel.replaceRange(3, 7, "****");
        response['person']['tel'] = tel;
      }
      return response;
    } catch (e) {
      print('Error during GET request: $e');
    }
  }

  Future postRemark<T>(dynamic params, [bool showLoading = true]) async {
    try {
      if (params['remark'] == ""){
        params['remark'] = "点击这里，填写简介";
      }
      Map<String, dynamic> response = await dioClient
          .post('$baseUrl/me/postRemark', queryParameters: params);
      if (response is Map) {
        return true;
      }else {
        return false;
      }
    } catch (e) {
      print('Error during post request: $e');
    }
  }

  Future getMePublish<T>([bool showLoading = true]) async {
    try {
      Map<String, dynamic> response = await dioClient
          .get('$baseUrl/me/getMePublish');
      if (response is Map) {
        return response['book'];
      }else {
        return [];
      }
    } catch (e) {
      print('Error during post request: $e');
    }
  }

  Future getMeCollect<T>([bool showLoading = true]) async {
    try {
      Map<String, dynamic> response = await dioClient
          .get('$baseUrl/me/getMeCollect');
      if (response is Map) {
        return response['book'];
      }else {
        return [];
      }
    } catch (e) {
      print('Error during post request: $e');
    }
  }

  Future getMeLike<T>([bool showLoading = true]) async {
    try {
      Map<String, dynamic> response = await dioClient
          .get('$baseUrl/me/getMeLike');
      if (response is Map) {
        return response['book'];
      }else {
        return [];
      }
    } catch (e) {
      print('Error during post request: $e');
    }
  }

}
